﻿@{
    Layout = null;
    EBook Ebook = ViewBag.Ebook as EBook;
}
<!DOCTYPE html>
<html dir="ltr" mozdisallowselectionprint moznomarginboxes>
<head>
    <title>@Ebook.Title _在线阅读</title>
    <script src="~/Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="~/Scripts/pdfobject.js"></script>
    <style type="text/css">
        #pdf {
            margin: 2em auto;
            border: 1px solid #65452;
        }

            #pdf p {
                padding: 1em;
            }

            #pdf object {
                display: block;
                border: solid 1px #123;
            }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            if (window.ActiveXObject || "ActiveXObject" in window) {

                //判断是否为IE浏览器，"ActiveXObject" in window判断是否为IE11
                //判断是否安装了adobe Reader
                for (x = 2; x < 10; x++) {
                    try {
                        oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');");
                        if (oAcro) {
                            flag = true;
                        }
                    } catch (e) {
                        flag = false;
                    }
                }
                try {
                    oAcro4 = new ActiveXObject('PDF.PdfCtrl.1');
                    if (oAcro4) {
                        flag = true;

                    }
                }
                catch (e) {
                    flag = false;
                }
                try {
                    oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
                    if (oAcro7) {
                        flag = true;
                    }
                }
                catch (e) {
                    flag = false;
                }
                if (flag) {
                    $('#pdf1').hide();
                }
                else {
                    alert("对不起,您还没有安装PDF阅读器软件呢,为了方便预览PDF文档,请选择安装！");
                    location = "http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/chs/AdbeRdr930_zh_CN.exe";
                }
            }
            else
            {
                var w = $(document).width() - 10;
                var h = $(document).height();
                $("#pdf").css("width", w).css("height", h);
                $.ajax({
                    url:'@ViewBag.FileLoad',
                    type:'HEAD',
                    error: function() {
                        alert("文件不存在，我们稍后会添加");
                        location.href="/EBook/Index";
                    },
                    success: function () {
                        $('#pdf1').show();
                        var success = new PDFObject({ url: "@ViewBag.FileLoad", pdfOpenParams: { scrollbars: '0', toolbar: '0', statusbar: '0' } }).embed("pdf");
                        if (!success) {
                            var a = "<object width='100%' height='100%' data='@ViewBag.FileLoad#scrollbars=0&toolbar=0&statusbar=0' type='application/pdf'>";
                            $("#pdf").html(a);
                        }
                    }
                });
            }
        };
</script>

</head>

<body>
    <p style="display:none">
        It appears you don't have Adobe Reader or PDF support in this web
        browser. <a href="@ViewBag.FileLoad">Click here to download the PDF</a>
    </p>
    <div id="pdf"></div>
</body>
</html>